#ifndef __SKYBOX_H__
#define __SKYBOX_H__ 1

#include <string>
#include <osg/Node>

osg::Node* createSkyBoxCubeMap(const std::string& cubemap, osg::StateSet* stateset = 0);

#endif

#include <iostream>
#include <cassert>

#include <osg/Geometry>
#include <osg/Depth>
#include <osg/TextureCubeMap>
#include <osg/TexEnv>
#include <osgDB/ReadFile>
#include <osgUtil/CullVisitor>

class SkyboxTransform : public osg::Transform
{
public:
	// Get the transformation matrix which moves from local coords to world coords.
	virtual bool computeLocalToWorldMatrix(osg::Matrix& matrix,
		osg::NodeVisitor* nv) const
	{
		osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(nv);
		if (cv)
		{
			osg::Vec3 eyePointLocal = cv->getEyeLocal();
			matrix.preMult(osg::Matrix::translate(eyePointLocal));
		}

		return true;
	}

	// Get the transformation matrix which moves from world coords to local coords.
	virtual bool computeWorldToLocalMatrix(osg::Matrix& matrix,
		osg::NodeVisitor* nv) const
	{
		osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(nv);
		if (cv)
		{
			osg::Vec3 eyePointLocal = cv->getEyeLocal();
			matrix.postMult(osg::Matrix::translate(-eyePointLocal));
		}

		return true;
	}
};

